<?php
class App_Admin_Service_Lang
{
	/**
	 * @var App_Admin_Model_Lang
	 */
	private $_modelLang;
	
	/**
	 * @return void
	 */
	public function __construct() 
	{
		$this->_modelLang = Main_Model::factory('Admin_Model_Lang');
	}

	/**
	 * @return int
	 */
	public function getLangId()
	{
		$langAbbr = Zend_Registry::getInstance()->langAbbr;
		return $this->_modelLang->getLangIdByAbbr($langAbbr);
	}
	
	/**
	 * @var App_Admin_Model_Lang
	 */
	public function getModelLang()
	{
		return $this->_modelLang;
	}
	
/**
	 * @param array $data
	 * @return bool
	 */
	public function insertItem($data)
	{
		return $this->_modelLang->insertItem($data);
	}
	
	/**
	 * @param array $data
	 * @param int $langId
	 * @return bool
	 */
	public function updateItem($data, $langId)
	{
		return $this->_modelLang->updateItem($data, $langId);
	}
	
	/**
	 * @param int $id
	 * @return array
	 */
	public function getItemById($id) 
	{
		return $this->_modelLang->getItemById($id);
	}
	
	/**
	 * @param string $abbr
	 * @return array
	 */
	public function getItemByAbbr($abbr) 
	{
		return $this->_modelLang->getItemByAbbr($abbr);
	}
	
	/**
	 * @return array
	 */
	public function getAll() 
	{
		$list =  $this->_modelLang->getAll();
		return $list;
	}
	
	/**
	 * @return array
	 */
	public function getAllIdAndName() 
	{
		$list =  $this->_modelLang->getAll();
		$list = Main_Function::expandList($list, 'id', 'name');
		
		return $list;
	}
	
	/**
	 * @param int $id
	 * @return bool
	 */
	public function deleteItem($id) 
	{
		return $this->_modelLang->deleteItem($id);
	}
	
	/**
     * @param string $value 
     * @param null $otherCond 
     * @return bool
     */
    public function checkUnique ($value, $otherCond = null)
    {
        $list = $this->getItemByAbbr($value);
        return empty($list) ? true : false;
    }
	
	
}
